/*
 * @Author: your name
 * @Date: 2020-05-18 09:55:07
 * @LastEditTime: 2020-08-10 16:45:09
 * @LastEditors: caiwenqi
 * @Description: In User Settings Edit
 * @FilePath: \richgo-vue-multipage-cdn-h5\config\index.js
 */
/**
 * 此处可修改环境配置
 *
 * @author yangjinlai 2019-07-30
 */

//获取当前ip
var localIp = (function(){
    var interfaces = require('os').networkInterfaces();
        for(var devName in interfaces){
            var iface = interfaces[devName];
            for(var i=0;i<iface.length;i++){
                var alias = iface[i];
                if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
                    return alias.address;
                }
            }
        }
})();


module.exports = function( env ){

	console.log('当前环境变量: ' + env)

	return {

		//cdn域名:
		cdnDomain: (function(){
			if( env == 4 ){
			    //非本地的其他环境
			    return  'https://richgolgbh5.chtwm.com/lgbCdn/assets/'
			}
			else if ( env == 0 ){
			    //本地
			    return '/'
			}
			else {
			    //非本地的其他环境
			    return  '/lgbCdn/assets/'
			}
		})(),


		// (env == 4) ? 'https://richgolgbh5.chtwm.com/lgbCdn/assets/' : '/',

		//用于页面上访问静态资源的域名
		publicPath: (function(){
			if( env == 4 ){
			    //非本地的其他环境
			    return  'https://richgolgbh5.chtwm.com/lgbCdn/assets/'
			}
			else if ( env == 0 ){
			    //本地
			    return '/'
			}
			else {
			    //非本地的其他环境
			    return  '/lgbCdn/assets/'
			}
		})(),

		// (env == 4) ? 'https://richgolgbh5.chtwm.com/lgbCdn/assets/' : '/',

		//直接拼完整的埋点文件链接
		mdUrl: (function(){

			var md = 'http://dc.qasa.chtwm.com';

			if( env == 1 || env == 2 ){
			    //测试
			    md = 'http://dc.qasa.chtwm.com';
			}
			else if( env == 3){
			    //预生产
			    md = 'https://dc.uata.haomalljf.com';
			}
			else if( env == 4 || env == 6){
			    //生产
			    md = 'https://dc.chtwm.com';
			}

			var mdUrl = md + '/htmd/min/baseMd.min.js?v=' + Math.random();

			return mdUrl;

		})(),

		//本地ip
		ip: localIp,

		//本地服务端口
		port: 8000,

		//接口转发
		proxyTable: {

			// '/api': {
			// 	target: "http://" + localIp + ":" + 7079 ,  //本地，mock接口默认设置为7079
			// 	//target: 'http://172.16.163.91:78',
			//     changeOrigin: true,
			//     secure: false,
			// },
			'/api': {
				target: "http://" + localIp + ":" + 8079 ,  //本地，mock接口默认设置为7079
				// target: 'http://172.16.163.68:8311', // 测试
				// target: 'http://172.16.163.54:8030', // 开发环境
			    changeOrigin: true,
			    secure: false,
			}

	    }
	}
}
